<?php
/*
 * @Author: your name2
 * @Date: 2021-09-21 16:46:35
 * @LastEditTime: 2022-02-28 20:11:40
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /nlog/app/Http/Controllers/AdminController/Login.php
 */

namespace App\Http\Controllers\crm;


use Illuminate\Support\Facades\Request;
use App\Models\admin_model\Admins as AdminDb;                        // admins表



class Admins extends BaseController
{

     public function mineMsg()
     {
          return $this->create(200, '查询成功', $this->getAdminInfo());
     }

     public function mineMsgEdit()
     {
          if (Request::has('formData')) {
               $formData = Request::input('formData');
               if (isset($formData['passWord'])) {
                    $formData['passWord'] = md5($formData['passWord']);
               }

               $admins_id = $this->getAdminId();
               $res =  redis_mysql_edit_return('admins', ['id' => $admins_id], $formData);
               if ($res) {
                    return $this->create(200, '编辑成功');
               } else {
                    return $this->create(100, '编辑失败');
               }
          }
     }

     public function checkUserName()
     {
          if (Request::has('userName')) {
               $res =    AdminDb::checkUserName(Request::input('userName'));

               if ($res) {
                    $admin_id = $this->getAdminId();
                    if ($res['id'] ==  $admin_id) {
                         return $this->create(200, '该账号可以使用', ['result' => 'success']);
                    }
                    return $this->create(200, '该账号已存在', ['result' => 'error']);
               } else {
                    return $this->create(200, '该账号可以使用', ['result' => 'success']);
               }
          }
     }

     public function adminsList()
     {
          $whereStr = '';
          $limitStr = '';
          if (Request::input('pageSize') && Request::input('page')) {
               $limitStr =   limit_joint(Request::input('page'), Request::input('pageSize'));
          }
          if (Request::has('keyWord')) {
               $keyWord = array_filter(Request::input('keyWord'), 'filtrfunction');
               if (!empty($keyWord)) {
                    $whereStr .= havaWhereLikeJoinEqual($keyWord);
               }
          }


          $list  =   AdminDb::selList($whereStr, $limitStr);
          return $this->create(200, '查询成功', ['list' => $list]);
     }
}
